{{ template "common/head.html" .title}}
<body>
{{ template "common/header.html" .userName }}

{{ template "common/search_bar.html" .goodsSKUCount}}

{{ template "common/navbar_con.html" .goodsTypes}}

<div class="breadcrumb">
    <a href="/">全部分类</a>
    <span>></span>
    <a href="/goods-list?type-id={{ .goodsType.Id }}">{{ .goodsType.Name }}</a>
</div>

<div class="main_wrap clearfix">
    <div class="l_wrap fl clearfix">
        <div class="new_goods">
            <h3>新品推荐</h3>
            <ul>
                {{ range .newGoodsSKUs }}
                    <li>
                        <a href="/goods-detail?id={{ .Id }}"><img src="http://192.168.181.130:8888/{{  .Image }}"></a>
                        <h4><a href="/goods-detail?id={{ .Id }}">{{ .Name }}</a></h4>
                        <div class="prize">￥{{ .Price }}</div>
                    </li>
                {{ end }}
            </ul>
        </div>
    </div>

    <div class="r_wrap fr clearfix">
        <div class="sort_bar">
            <a href="/goods-list?type-id={{ .goodsTypeId }}" {{ if compare .sortType "" }} class="active" {{ end }}>默认</a>
            <a href="/goods-list?type-id={{ .goodsTypeId }}&sort=price" {{ if compare .sortType "price" }} class="active" {{ end }}>价格</a>
            <a href="/goods-list?type-id={{ .goodsTypeId }}&sort=sale" {{ if compare .sortType "sale" }} class="active" {{ end }}>人气</a>
        </div>

        <ul class="goods_type_list clearfix">
            {{ range .goodsSKUs }}
                <li>
                    <a href="/goods-detail?id={{ .Id }}"><img src="http://192.168.181.130:8888/{{ .Image }}"></a>
                    <h4><a href="/goods-detail?id={{ .Id }}">{{ .Name }}</a></h4>
                    <div class="operate">
                        <span class="prize">￥{{ .Price }}</span>
                        <span class="unit">{{ .Price }}/{{ .Unite }}</span>
                        <a href="javascript:;" class="add_goods" title="加入购物车" goods_sku_id="{{ .Id }}"></a>
                    </div>
                </li>
            {{ end }}
        </ul>

        <div class="pagenation">
            <a href="/goods-list?type-id={{ .goodsTypeId }}&page-index={{ .prePageIndex }}&sort={{ .sortType }}">
                <上一页
            </a>
            {{ range $index,$value := .pages }}
                {{ if compare $.pageIndex $value }}
                    <a href="/goods-list?type-id={{ $.goodsTypeId }}&page-index={{ $value }}&sort={{ $.sortType }}"
                       class="active">{{ $value }}</a>
                {{ else }}
                    <a href="/goods-list?type-id={{ $.goodsTypeId }}&page-index={{ $value }}&sort={{ $.sortType }}">{{ $value }}
                    </a>
                {{ end }}
            {{ end }}
            <a href="/goods-list?type-id={{ $.goodsTypeId }}&page-index={{ $.nextPageIndex }}&sort={{ .sortType }}">下一页></a>
        </div>
    </div>
</div>

{{ template "common/footer.html"}}
<script type="text/javascript">

    $('.add_goods').click(function () {
        goods_sku_id = $('.add_goods').attr('goods_sku_id')
        goods_count = 1

        param = {"goods_sku_id": goods_sku_id, "goods_count": goods_count}
        $.post('/u/add-cart', param, function (data) {
            if (data.code == 0) {
                $('.goods_count').html(data.goodsSKUCount);
            } else {
                if (data.userName != ""){
                    // 已登录
                    alert(data.msg);
                } else {
                    // 未登录
                    alert("未登录，请登录~");
                    window.location.href = '/login';
                }
            }
        })
    })
</script>
</body>
</html>